<template>
    <div>
        <div id="lineone">
            <div class="item">
                <label class="textspan">用户名:</label>
                <div><input type="text" v-model="username" name="username" placeholder="请输入您的手机号"></div>
            </div>
            <div class="item">
                <label class="textspan">密&emsp;码:</label>
                <div><input type="password" v-model="psw" name="psw" placeholder="数字字母下划线4-16位"></div>
            </div>
            <div class="item">
                <label class="textspan">验证码:</label>
                <div><input type="text" id="lastinput" placeholder="请输入验证码" v-model="captcha" name="captcha" required></div>
            </div>
        </div>
        <div>
            <img src="/api/captcha" alt="" id="captcha">
            <button type="button" @click="refresh">看不清,换一张</button>
        </div>
        <div class="lastline">
            <div id="twoweek"><input type="checkbox">两周内自动登录</div>
            <div class="ps">忘记密码</div>
        </div>
        <button id="loginbtn" @click="loginbtn">登录</button>
    </div>
</template>

<script>
import { Toast } from 'mint-ui'
export default {
    data: function() {
        return {
            username: "",
            psw: "",
            captcha: ""
        }
    },
    methods: {
        refresh: function() {
            var captcha = document.getElementById("captcha");
            captcha.setAttribute("src", "/api/captcha?" + Math.random());
        },
        loginbtn: function() {
            var params = {
                username: this.username,
                psw: this.psw,
                captcha: this.captcha
            }
            this.http.post("/api/login", params)
                .then(res => {
                    // console.log(res.data);
                    Toast({
                        message: res.data.msg,
                        position: 'middle',
                        duration: 1000
                    });
                    if (res.data.msg == "登录成功") {
                        location.hash = "/";
                    }
                })
        }
    }
}
</script>

<style scoped>
#lineone {
    background-color: #fff;
    /*border: solid 1px black;*/
    /*height: 100px;*/
}

.textspan {
    width: 20vw;
    /*border: solid 1px red;*/
    padding-left: 10px;
    line-height: 40px;
    color: #666;
    font-size: 14px;
}

.item {
    height: 40px;
    border-bottom: 1px solid #dcdcdc;
    display: flex;
    line-height: 40px;
}

input {
    height: 25px;
    background-color: rgb(250, 255, 189);
    width: 200px;
    border: none;
}

#lastinput {
    width: 40vw;
    height: 30px;
    background-color: white;
}

.lastline {
    margin-top: 20px;
    height: 20px;
    clear: both;
}

#loginbtn {
    height: 33px;
    width: 92vw;
    background-color: orange;
    border: none;
    color: white;
    border-radius: 5px;
}

.ps {
    color: #eda200;
    font-size: 14px;
    float: right;
    margin-right: 5px;
}

#twoweek {
    color: #666;
    font-size: 14px;
    float: left;
    margin-left: 5px;
    line-height: 20px;
    /*vertical-align: middle;*/
}

#twoweek input {
    height: 15px;
    width: 15px;
}
</style>